<%--
  Created by IntelliJ IDEA.
  User: 小袁啊
  Date: 2024/10/30
  Time: 下午6:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%--引入vue--%>
    <script src="../js/vue.js"></script>
    <%--引入axios--%>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <h2 style="color: #009688">密码修改</h2>
    <div>
        <el-form label-position="right" label-width="200px" :model="formPassWord">
            <el-form-item label="旧密码">
                <el-input placeholder="请输入旧密码" v-model="formPassWord.oldPassWord" show-password></el-input>
            </el-form-item>
            <el-form-item label="新密码">
                <el-input placeholder="请输入新密码" v-model="formPassWord.newPassWord" show-password></el-input>
            </el-form-item>
            <el-form-item label="请确认新密码">
                <el-input placeholder="请再次输入密码" v-model="formPassWord.replaceNewPassWord"
                          show-password></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="confirmUpdate">确定修改</el-button>
            </el-form-item>
        </el-form>
    </div>

</div>
</body>
<script>
    let app = new Vue({
        el: "#app",
        data: {
            formPassWord: {},//密码修改表单
        },
        created() {

        },
        methods: {
            /*确认修改*/
            confirmUpdate() {
                // 判断新密码与确认密码是否一致
                if (this.formPassWord.newPassWord == this.formPassWord.replaceNewPassWord) {
                    axios.get('/login/updatePassWord?oldPassWord=' + this.formPassWord.oldPassWord +
                        '&newPassWord=' + this.formPassWord.newPassWord).then(res => {
                        if (res.data.code === 200) {
                            this.$notify({
                                title: '3秒后将到登录界面',
                                message: res.data.msg,
                                duration: 0,
                                type: 'success'
                            });
                            setTimeout(function () {
                                window.parent.location.href = "../login.jsp"
                            }, 3000)
                        }else if (res.data.code === 500) {
                            this.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                    })
                } else {
                    this.$message({
                        message: '密码格式错误或者与原密码不符！',
                        type: 'warning'
                    });
                }
                //console.log(this.formPassWord)
            }
        }
    })
</script>
</html>
